package com.wwj.my_ummary.util.numberUtils;

import java.math.BigInteger;

/**
 * 数据类型转换工具类
 */
public class DataTypeUtil {

    public static boolean isEmpty(String s) {
        return null == s || "".equals(s) || "".equals(s.trim()) || "null".equalsIgnoreCase(s);
    }

    public static int getIntValue(Object o) {
        if (o == null) {
            return 0;
        }
        try {
            return Integer.parseInt(o.toString());
        } catch (Exception e) {
            return 0;
        }
    }

    public static int getIntValue(BigInteger o) {
        if (o == null) {
            return 0;
        }
        try {
            return Integer.parseInt(o.toString());
        } catch (Exception e) {
            return 0;
        }
    }

    public static int getIntValue(String o) {
        if (o == null) {
            return 0;
        }
        try {
            if (o.contains(".")) {
                return (int) (Double.parseDouble(o));
            } else {
                return Integer.parseInt(o);
            }
        } catch (Exception e) {
            return 0;
        }
    }

    public static double getDoubleValue(String o) {
        if (o == null) {
            return 0;
        }
        try {
            return Double.parseDouble(o);
        } catch (Exception e) {
            return 0;
        }
    }

    public static double getDoubleValue(Object o) {
        if (o == null) {
            return 0;
        }
        try {
            return Double.parseDouble(o.toString());
        } catch (Exception e) {
            return 0;
        }
    }

    public static long getLongValue(String o) {
        if (o == null) {
            return 0;
        }
        try {
            return Long.parseLong(o);
        } catch (Exception e) {
            return 0;
        }
    }

    public static long getLongValue(Object o) {
        if (o == null) {
            return 0;
        }
        try {
            return Long.parseLong(o.toString());
        } catch (Exception e) {
            return 0;
        }
    }

}
